package org.springboot.base.user.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springboot.base.user.does.UserDO;
import org.springboot.base.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZJL
 * @DateTime 2019年2月6日 上午12:10:52
 * 
 **/
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;

	@RequestMapping("/hello")
	public String hello(HttpServletRequest request) {
		HttpSession session = request.getSession();
		System.out.println("hello:"+session.getAttribute("userName"));
		return "hello world";
	}
	
	@RequestMapping("/getUser")
	public UserDO getUser(Long userId) {
		System.out.println("getUser");
		return this.userService.getUser(userId);
	}

	@RequestMapping("/list")
	public List<UserDO> listUser() {
		return this.userService.listUser();
	}
	@RequestMapping("/listUser")
	public List<UserDO> listUser(String userName) {
		return this.userService.listUser(userName);
	}

	@RequestMapping("/addUser")
	public UserDO addUser(UserDO user) {
		return this.userService.addUser(user);
	}

	@RequestMapping("/updateUser")
	public UserDO updateUser(UserDO user) {
		return this.userService.updateUser(user);
	}

	@RequestMapping("/deleteUser")
	public int deleteUser(Long userId) {
		return this.userService.deleteUser(userId);
	}
	
}
